var iswx = false;
apiready = function(){

if(api.connectionType=='none'){
			error();
			  var reloading = $api.byId('reloading');
			  $api.addEvt(reloading, 'click', function(){
			  	_openFrame(4)
			  });
			  	return;
  	
  			}
	/*var activity = api.require('UILoading');
	var aa = [{
        		frame: 'widget://image/che.png'
    	     },
    	     {
    	     	frame: 'widget://image/shu.png'
    	     }
    	    ];
    	     alert(JSON.stringify(aa));
activity.keyFrame({
    rect: {
        w: 80,                              
        h: 80    
    },
    styles: {
        bg: 'rgba(0,0,0,0.5)',
        corner: 5, 
        interval: 50,
        frame:{ 
            w: 80, 
            h: 80
        }},
        content: aa
    
}, function(ret){   
    alert(JSON.stringify(ret));
});*/
  userReload()
}
//function cs(){
//var qq = api.require('qq');
//  		qq.installed(function(ret, err) {
//			    if (ret.status) {
//			        //api.alert({ msg: "安装" });
//			    } else {
//			        location.href="tel:4000980299";
//			        return false;
//			    }
//				});
//	if (api.systemType == "android") {
//	
//		location.href='mqqwpa://im/chat?chat_type=wpa&uin=330285341';
//	}else{
//		location.href = 'mqq://im/chat?chat_type=wpa&uin=330285341&version=1&src_type=web';
//	}
//}
function cs(){
var	user = $api.getStorage('user');
var avatar = null;
var mq = api.require('meiQia');
mq.show();

if(user){
		if(isImg(user.img)){
	     	avatar ="http://wap.jqmao.cn/statics/uploads/"+user.img+"_160160.jpg";
	     }else if(isPng(user.img)){
	     	 avatar ="http://wap.jqmao.cn/statics/uploads/"+user.img+"_160160.png";
	     }else{
	    	 avatar =""+user.img;
		 }   
		
		
		var infoParam = {
		    name:""+user.username,
		    tel:""+user.mobile,
		    address:""+user.user_ip,
		    comment: "ID号："+user.uid,
		    avatar: ""+avatar,
		    tags: ["付费用户", "使用疑问"]
		};
		mq.setClientInfo(infoParam);
		var customizedIdParam = {
    		id: ""+user.uid,
		};
		mq.setLoginCustomizedId(customizedIdParam);
}
	

}
function userReload(){

var systemType = api.systemType;

	if(systemType=='ios'){
						api.ajax({
					    url:'http://wap.jqmao.cn/hide'
				    },function(ret,err){
				    	//coding...
				    	//alert(ret.value)
				    	if(ret.value=='1'){
				    	//alert(ret.value)
				    	 	iswx = false;
				    	 	
				    	}else{
				    		iswx = true;
				    	}
				    });
				}else{
					iswx = true;
				}                   
                            
/*var username = $api.getStorage('user').username;
	
	var	uid = $api.getStorage('user').uid;
	var push = api.require('push');
	push.bind({
	    userName:''+username,
	    userId:''+uid
	},function(ret,err){
	    if(ret.status){
	       api.alert({msg:'绑定成功'});
	    }else{
	        //api.alert({msg:err.msg});
	    }
	});*/
	   var user = null;

        var _user = $api.getStorage('user');
        

      if(_user){
     
       var uid =_user.uid;
       
         api.ajax({
        url: 'http://wap.jqmao.cn/updateUser',
        method: 'post',
        data: {
            values: {uid: uid}
        }
    }, function (ret, err) {
        if(ret){
            $api.setStorage('user',ret);
            user = $api.getStorage('user');
            user['iswx'] = iswx;
            //alert(user['iswx']);
        	//广播user
            api.sendEvent({
					    name: 'user',
					    extra: {
					        jingyan: user.jingyan,  
					        username: user.username,
					        uid: user.uid,
					        money: user.money, 
					        thumb:user.thumb
					    }
					});
					
            var a =$api.byId('my');
            var tpl = $api.byId('user-template').text;
            var tempFn = doT.template(tpl);
            $api.html(a,tempFn(user));
           /* alert(JSON.stringify(ret));*/
        }else{
            //alert(JSON.stringify(err));
        }

    })
      }else{
      var ret = '';
      	$api.setStorage('user',ret);
            user = $api.getStorage('user');
            
            var a =$api.byId('my');
            var tpl = $api.byId('user-template').text;
            var tempFn = doT.template(tpl);
            $api.html(a,tempFn(user));
      }	 
 		
		
 }
 